<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>门店菜品销量图表</title>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/page.css"/>
</head>
<body>
<div id="app">
    <div class="dashboard-container1" id="category-app">
        <div class="container1">
            <!--表格-->
            <el-table
                    :data="tableData"
                    stripe
                    width="60%"
                    class="tableBox1"
                    style="width: 538px"
            >
                <el-table-column
                        type="index"
                        width="50"
                >
                </el-table-column>
                <el-table-column
                        prop="name"
                        label="店铺名称"
                >
                </el-table-column>

                <el-table-column
                        prop="totalNums"
                        label="商品总数(种)"
                        align="center"
                >
                </el-table-column>

                <el-table-column
                        prop="totalSals"
                        label="销售总量(份)"
                        align="center"
                >
                </el-table-column>

                <el-table-column
                        label="操作"
                        width="160"
                        align="center"
                >
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                size="small"
                                class="blueBug"
                                @click="show(scope.row.categoryId,scope.row.name)"
                        >
                            查看商品售卖图表
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    class="pageList1"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="counts"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
            ></el-pagination>
        </div>
        <div id="echarts" style="margin-top: 92px">
            <!--占位子-->
            <div id="monitorZhuZhe" style="width: 600px;height:400px;"></div>
        </div>
        <!--图表详情-->
        <el-dialog
                :title="classData.title"
                :visible.sync="classData.dialogVisible"
                :before-close="handleClose"
                width="954px"
        >
            <div style="display: flex;justify-content: space-between">
                <div>
                    <el-table
                            :data="dishDetails"
                            stripe
                            width="30%"
                            class="tableBox1"
                            style="width: 385px"
                    >
                        <el-table-column
                                type="index"
                                width="50"
                        >
                        </el-table-column>
                        <el-table-column
                                prop="name"
                                label="商品名"
                        >
                        </el-table-column>

                        <el-table-column
                                prop="totalSal"
                                label="商品销量"
                                align="center"
                        >
                        </el-table-column>
                    </el-table>
                </div>
                <div>
                    <div id="monitorDishBing" style="width: 500px;height:500px;"></div>
                </div>
            </div>


        </el-dialog>
    </div>
</div>

</body>
<script src="../../plugins/vue/vue.js"></script>
<script src="../../plugins/element-ui/index.js"></script>
<link rel="stylesheet" href="../../plugins/element-ui/index.css">
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/store.js"></script>
<script src="../../js/echarts.js"></script>

<script>
    new Vue({
        el: "#app",
        mounted() {
        },
        created() {
            this.init()
        },
        methods: {
            async init() {
                await getStorePage({'page': this.page, 'pageSize': this.pageSize}).then(res => {
                    if (String(res.code) === '1') {
                        this.tableData = res.data.records || []
                        this.counts = Number(res.data.total)
                        for (const k in this.tableData) {
                            this.shopName.push(this.tableData[k].name)
                            this.shopSales.push(this.tableData[k].totalSals)
                        }
                        this.getMychart()
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                })

            },
            //店铺echart图
            getMychart() {
                //页面加载完毕
                var myChart = echarts.init(document.getElementById('monitorZhuZhe'));//main 中放了一个折线图和柱状图
                var charOption;
                charOption = {
                    title: {
                        text: '各门店销售量',
                        textStyle: {
                            //文字颜色
                            color: '#909399',
                            //字体风格,'normal','italic','oblique'
                            fontStyle: 'normal',
                            //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
                            fontWeight: 'bold',
                            //字体系列
                            fontFamily: 'sans-serif',
                            //字体大小
                            fontSize: 20
                        }
                    },
                    xAxis: {
                        data: this.shopName,
                        type: 'category',
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: this.shopSales,
                            type: 'line',
                        },
                        {
                            data: this.shopSales,
                            type: 'bar',
                        }
                    ]
                };
                myChart.setOption(charOption, true)
            },
            //菜品echart图
            getMyDishChart() {
                var myChart1 = echarts.init(document.getElementById('monitorDishBing'));
                var option;
                option = {
                    backgroundColor: '#2c343c',
                    title: {
                        text: '菜品销量 饼状图',
                        left: 'center',
                        top: 20,
                        textStyle: {
                            color: '#ccc'
                        }
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    visualMap: {
                        show: false,
                        min: 80,
                        max: 600,
                        inRange: {
                            colorLightness: [0, 1]
                        }
                    },
                    series: [
                        {
                            name: 'Access From',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '50%'],
                            data: this.dishSales
                                .sort(function (a, b) {
                                return a.value - b.value;
                            }),
                            roseType: 'radius',
                            label: {
                                color: 'rgba(255, 255, 255, 0.3)'
                            },
                            labelLine: {
                                lineStyle: {
                                    color: 'rgba(255, 255, 255, 0.3)'
                                },
                                smooth: 0.2,
                                length: 10,
                                length2: 20
                            },
                            itemStyle: {
                                color: '#c23531',
                                shadowBlur: 200,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            },
                            animationType: 'scale',
                            animationEasing: 'elasticOut',
                            animationDelay: function (idx) {
                                return Math.random() * 200;
                            }
                        }
                    ]
                };
                myChart1.setOption(option, true)
                this.dishSales=[]
            },
            //查看菜品售卖图标
            show(categoryId, name) {
                this.classData.dialogVisible = true
                this.classData.title = name
                getDishByCategoryId(categoryId).then(res => {
                    this.dishDetails = res.data || []
                    for (const k in this.dishDetails) {
                        this.dishSales.push(
                            {value:this.dishDetails[k].totalSal,name:this.dishDetails[k].name}
                        )
                    }
                    this.getMyDishChart()
                })
            },
            handleSizeChange(val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange(val) {
                this.page = val
                this.init()
            },
            // 关闭弹窗
            handleClose(st) {
                this.classData.dialogVisible = false
            },
        },
        data() {
            return {
                tableData: [],
                shopName: [],
                shopSales: [],
                dialogVisible: false,
                classData: {
                    'title': '添加菜品分类',
                    'dialogVisible': false,
                    'categoryId': '',
                    'name': '',
                    sort: ''
                },
                dishDetails: [],
                dishSales:[],
                counts: 0,
                page: 1,
                pageSize: 10,
            }
        }
    })
</script>
</html>